//获取应用实例
const app = getApp();

Page({
	data: {
    oldpwdId:'',
    newpwdId:'',
    newpwdagainId:'',

  },
	onLoad: function() {

  },

  oldpwdInput: function (e) {
    var that = this;
    that.setData({
      oldpwdId: e.detail.value
    })
  },
  newpwdInput: function (e) {
    var that = this;
    that.setData({
      newpwdId: e.detail.value
    })
  },
  newpwdagainInput: function (e) {
    var that = this;
    that.setData({
      newpwdagainId: e.detail.value
    })
  },

  //修改密码
  changePwd:function(){
    var that=this;
    if (this.data.oldpwdId.length == 0) {
      wx.showToast({
        title: '请输入原密码',
        icon: 'none'
      })
      return;
    }
    if (this.data.newpwdId.length == 0) {
      wx.showToast({
        title: '请输入新密码',
        icon: 'none'
      })
      return;
    }
    if (this.data.newpwdagainId.length == 0) {
      wx.showToast({
        title: '请输入重复新密码',
        icon: 'none'
      })
      return;
    }
    wx.request({
      url: app.globalData.api + '/app.php?c=User&a=changePwd',
      data: {
        token:app.globalData.token,
        oldpwd: that.data.oldpwdId,//原密码
        pwd1: that.data.newpwdId,//密码
        pwd2: that.data.newpwdagainId,//重复新密码
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded",
        'platform': '' + app.globalData.platform,
        'version': '' + app.globalData.version,
      },
      method: 'POST',
      dataType: 'json',
      success: function (res) {
        console.log(res);
        if (res.data.code == 0) {
          wx.showToast({
            title: '' + res.data.msg,//提示文字
            duration: 2000,//显示时长
            mask: true,//是否显示透明蒙层，防止触摸穿透，默认：false  
            icon: 'success', //图标，支持"success"、"loading"  
            success: function () { },//接口调用成功
            fail: function () { },  //接口调用失败的回调函数  
            complete: function () { } //接口调用结束的回调函数  
          })
          setTimeout(function () {
            //要延时执行的代码
            wx.navigateBack({
              delta: 1
            })
          }, 1000) //延迟时间 这里是1秒

        } else{
          wx.showToast({
            title: '' + res.data.msg,//提示文字
            duration: 2000,//显示时长
            mask: true,//是否显示透明蒙层，防止触摸穿透，默认：false  
            icon: 'none', //图标，支持"success"、"loading"  
            success: function () { },//接口调用成功
            fail: function () { },  //接口调用失败的回调函数  
            complete: function () { } //接口调用结束的回调函数  
          })
        }
        
      }, fail: function () {

      }
    });
  },


});
